package co.fitstart.coach.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dynamic;

import co.fitstart.coach.dao.CoachDao;
import co.fitstart.coach.service.CourseHourService;
import co.fitstart.entity.coach.CoachSigninRecord;
import co.fitstart.entity.coach.CoachSigninStatistic;
import co.fitstart.entity.principal.Principal;

@Service("courseHourService")
public class CourseHourServiceImpl implements CourseHourService{
    
    @Dynamic
    private CoachDao coachDao;
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseHourService#listCoachSigninStatistic(co.fitstart.entity.principal.Principal)
     */
    public List<CoachSigninStatistic> listCoachSigninStatistic(Principal coach) {
        return coachDao.listCoachSigninStatistic(coach);
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseHourService#loadCoachSigninStatistic(java.lang.Long)
     */
    public CoachSigninStatistic loadCoachSigninStatistic(Long statisticId) {
        return genericDaoSupport.load(CoachSigninStatistic.class, statisticId);
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseHourService#listCoachSigninRecord(co.fitstart.entity.principal.Principal, java.lang.String)
     */
    public List<CoachSigninRecord> listCoachSigninRecord(Principal coach, String month) {
        return coachDao.listCoachSigninRecord(coach, month);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseHourService#listCoachExperienceSigninStatistic(co.fitstart.entity.principal.Principal)
     */
    public Map<String, BigDecimal> listCoachExperienceSigninStatistic(Principal coach) {
        List<Map<String, Object>> mapList = coachDao.listCoachExperienceSigninStatistic(coach);
        
        if(mapList.isEmpty()) {
            return null;
        } else {
            Map<String, BigDecimal> result = new HashMap<>();
            
            for(Map<String, Object> map : mapList) {
                result.put((String)map.get("month"), (BigDecimal)map.get("total"));
            }
            
            return result;
        }
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseHourService#getCoachExperienceSigninStatistic(co.fitstart.entity.principal.Principal, java.lang.String)
     */
    public BigDecimal getCoachExperienceSigninStatistic(Principal coach, String month) {
        return coachDao.getCoachExperienceSigninStatistic(coach, month);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseHourService#listCoachHideStatistic(co.fitstart.entity.principal.Principal)
     */
    public Map<String, BigDecimal> listCoachHideStatistic(Principal coach) {
        List<Map<String, Object>> mapList = coachDao.listCoachHideStatistic(coach);
        
        if(mapList.isEmpty()) {
            return null;
        } else {
            Map<String, BigDecimal> result = new HashMap<>();
            
            for(Map<String, Object> map : mapList) {
                result.put((String)map.get("month"), (BigDecimal)map.get("total"));
            }
            
            return result;
        }
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseHourService#getCoachHideStatistic(co.fitstart.entity.principal.Principal, java.lang.String)
     */
    public BigDecimal getCoachHideStatistic(Principal coach, String month) {
        return coachDao.getCoachHideStatistic(coach, month);
    }
}
